The present invention relates to methods and devices for controlling access to physical memory in computer systems using virtual memory techniques.
To allow many processes to share a limited amount of physical memory in a computer system, modern operating systems (such as Sun Microsystem""s Solaris(trademark) operating system (xe2x80x9cOSxe2x80x9d)) implement virtual memory, which provides a mapping between a process""s virtual address space and physical addresses. The operation of virtual memory in a computer system is described in John L. Hennessey and David A. Patterson, Computer Architecture: A Quantitative Approach, pp. 427-472 (2d ed. 1995), which is incorporated herein by reference.
Since more than one process may map its virtual addresses to the same physical location, tagging is necessary to identify which process is currently attempting to access memory. These tags are referred to as contexts. When a process attempts to access a (virtual) address, the process presents this address and the context to a memory management unit (xe2x80x9cMMUxe2x80x9d). The MMU then consults appropriate data structures that store either all or some subset of virtual-to-physical translations used by the system. These data structures may, for example, be organized as a table, a hierarchy of tables or a linked list. These data structures will be referred to hereafter as xe2x80x9cmapping structures.xe2x80x9d Such address translations are often cached in a special mapping structure called a translation lookaside buffer (xe2x80x9cTLBxe2x80x9d), which may have hardware support for speed of accessing translation entries.
The operating system may need to invalidate (demap) the address space of a particular process. Demapping may occur, for example, when a process exits and the OS decides to reuse the context for another process. If the mapping structure resides in memory, rather than in special purpose hardware that supports associative searching, demapping a context may require scanning the whole mapping structure. For very large mapping structures, scanning the structure can present a performance problem. For example, the OS needs to be certain that a context demapping operation has completed before the OS can proceed. Otherwise, another mapping for the same context and virtual address can be created, and, if two mappings exist, incorrect translations can occur. The scanning process to demap a process may take a long time to complete, degrading system performance. If the memory that stores the mapping structure is also used for other data, attempting to complete the demapping process as soon as possible will consume a substantial portion of the memory bandwidth, delaying satisfaction of requests from other clients trying to access non-mapping-structure data.
In accordance with an embodiment of the present invention, a method is presented for controlling virtual memory in a computer system with a plurality of process contexts. The system contains an address translation mapping structure with a plurality of address translation entries. Each translation entry includes a validity flag and a mapping indicator. A mapping indicator and a cleanup indicator are also maintained for each process context in a context table. When each translation entry is initialized, the entry""s validity flag is set and the mapping indicator is set equal to the mapping indicator for the associated context. A process context is demapped by changing the mapping indicator for the context and the cleanup indicator for the context. Memory accesses using a translation entry associated with the demapped context are invalidated since the mapping indicator for the entry does not match the mapping indicator for the context. This embodiment advantageously invalidates all the mapping structure entries associated with a demapped context by changing a single indicator.
In a further embodiment of the invention, a background process scans the cleanup indicator for each context. When the cleanup indicator for any context indicates that the context has been demapped, the process scans the mapping structure. The validity flag for an entry is cleared if the mapping indicator for the entry does not match the context mapping indicator for its associated context. All of the cleanup indicators that indicated that the associated context had been demapped at the start of the scan of the mapping structure are changed to indicate the background process was run, when the scan is completed.
In a memory management device embodiment of the present invention for a computer system, a mapping structure with a plurality of translation entries is included. Each translation entry includes a validity flag and a mapping indicator. A context mapping indicator and a cleanup indicator are provided for each of a plurality of process contexts in a context table. Logic is included that loads each translation entry by setting the entry""s validity flag and setting the mapping indicator for the entry equal to the mapping indicator for the associated context. Logic is included that demaps a process context by changing the mapping indicator for the context and the cleanup indicator for the context. Logic is further included that invalidates memory accesses that require translation entries associated with the demapped context, by checking that the mapping indicator for the entry does not match the mapping indicator for the context.